{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d979a37b",
   "metadata": {},
   "source": [
    "-------\n",
    "* 日期：2022.10.26\n",
    "* 课程: Python\n",
    "* 记录人:zhoubilian\n",
    "-------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34ec98e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "准备工作：\n",
    "product_list=[\n",
    "    \"自行车 299\"，\n",
    "    \"Iphone 14 Pro 8000\"，\n",
    "    \"NFT 盲盒 28\"，\n",
    "    \"许老师的Python书 80\"\n",
    "]\n",
    "#优化\n",
    "product_list=[\n",
    "    [ \"自行车\"，299]\n",
    "    [\"Iphone 14 Pro\"，8000]\n",
    "    [ \"NFT 盲盒 \"，28]\n",
    "    [\"许老师的Python书 80\"]\n",
    "]  \n",
    "shopping_car=[]\n",
    "1.Alipay= input(\"请输入余额:\")\n",
    "  print()\n",
    "  # 情景1：用户输入了商品编号：shopping\n",
    "2.user_choice=input(\"请输入商品编号：\")\n",
    "  # 0,1,2,3\n",
    "3.if 钱够，Alipay-商品的价格\n",
    "      shopping_car.append(product_list[user_choice])\n",
    "else print(\"您的余额已不足，请更换支付方式~\")\n",
    "4.# 情景2：用户输入“q”，退出购买\n",
    "  print(shopping_car)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e92fd9ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：16\n",
      "[['茶百道', 16], ['蜜雪冰城', 6], ['古茗', 16], ['益禾堂', 12], ['桃园三章', 10]]\n"
     ]
    }
   ],
   "source": [
    "product_list=[\n",
    "    [\"茶百道\",16],\n",
    "    [\"蜜雪冰城\",6],\n",
    "    [\"古茗\",16],\n",
    "    [\"益禾堂\",12],\n",
    "    [\"桃园三章\",10]\n",
    "]\n",
    "shopping_car=[product_list]\n",
    "Alipay=input(\"请输入余额：\")\n",
    "print(product_list)\n",
    "user_choice=input(\"请输入商品编号：\")\n",
    "if 钱够，Alipay-商品的价格\n",
    "    shopping_car.append(product_list[user_choice])\n",
    "else print(\"您的余额已不足，请更换支付方式~\")\n",
    "\n",
    "if user_choice.isdigit()and int(user_choice)<len(good_list)and int(user_choice)>=0:\n",
    "    user_choice=int(user_choice)\n",
    "    if Alipay>good_list[user_choice][1]:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0e192bb7",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (1887338128.py, line 25)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [7]\u001b[1;36m\u001b[0m\n\u001b[1;33m    elif user_choice== \"q\":\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "product_list=[\n",
    "    [ \"自行车\",299],\n",
    "    [\"Iphone 14 Pro\",8000],\n",
    "    [ \"NFT 盲盒 \",28],\n",
    "    [\"许老师的Python书 \",80]\n",
    "]  \n",
    "shopping_car=[]\n",
    "\n",
    "Alipay=int(input(\"请输入余额：\"))\n",
    "while True:\n",
    "    print(\"------商品列表------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品编号\"+str(i),product_list[i])\n",
    "    user_choice=input(\"请输入商品编号:\")\n",
    "    #情景1：用户输入商品编号：shopping\n",
    "    if user_choice.isdigit():\n",
    "      # 判断钱够不够，商品是谁？==>product_list[user_choice][1]\n",
    "      if Alipay>=product_list[int(user_choice)][1]:\n",
    "            Alipay=Alipay - product_list[int(user_choice)][1]# m买完商品剩余的钱\n",
    "            shopping_car.append(product_list[int(user_list)])\n",
    "            print(\"您购买的商品已增加到购物车~~您的余额还有:\",Alipay)\n",
    "    else:\n",
    "        print(\"您的余额不足，请更换支付方式\")\n",
    "    # 情景2：用户输入“q”，退出购买\n",
    "    elif user_choice== \"q\":\n",
    "        print(\"您的购物车:\",shopping_car)\n",
    "        print(\"您的余额还有：\"，Alipay)\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或输入有误，请重新输入\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e32395c6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
